package Offer.offer;


import domain.ListNode;

import java.util.Stack;

/**
 * 从尾到头打印链表
 *
 * @author leiwenkang
 * @date 2020/4/6
 */
public class Test05从尾到头打印链表 {

    public static void printListNodeReversely(ListNode head) {
        Stack<Integer> stack = new Stack<>();

        ListNode p = head;
        while (p != null) {
            stack.add(p.val);
            p = p.next;
        }

        while (!stack.isEmpty()) {
            System.out.println(stack.pop());
        }
    }
}

